<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>淘惠帮</title>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="${resources}/css/common.css" type="text/css">
    <link rel="stylesheet" href="${resources}/plugins/fontAwesome/4.6.3/css/font-awesome.min.css" type="text/css">
    <link rel="stylesheet" href="${resources}/css/orderPayDetail.css" type="text/css">
        <#include "setwxshare.ftl"/>
</head>
<body>
    <div id="container">
        <div class="content">

            <div class="commonHeader">订单支付
            	<a href="javascript:history.go(-1);" class="fa fa-chevron-left back"></a>
            </div>
            <!--订单信息-->
            <div class="conTop">
            	<!-- 
                <div class="payTimer"><span>支付剩余时间<br/>14:25</span></div>
            	 -->
            	 <#list orderPlat.orderList as order>
            	 <#list order.orderItemList as item>
                <div class="goodInfo">
                    <div class="goodImg"><img src="${item.goods.picurl}" ></div>
                    <p>${item.price}</p>
                    <p><span>${item.goods.name}</span> x${item.amount}</p>
                </div>
                </#list>
                </#list>
            </div>
            <!--支付方式-->
            <div class="conMid">
            	<!-- 
                <div class="bankCard">
                    <div class="cardImg"><img src="${resources}/images/card.png" ></div>
                    <p>银行卡支付</p>
                    <p class="cr">使用商业银行卡支付立减20元</p>
                    <input type="radio" name="payType">
                </div>
            	 -->
                <div class="weixin">
                    <div class="cardImg"><img src="${resources}/images/wx.png" ></div>
                    <p>微信支付 </p>
                    <p class="cr1">推荐安装5.0版本以上用户使用</p>
                    <input type="radio" name="payType" checked="true">
                </div>
            </div>
            <botton class="sendBtn"  onclick="goWxPay()">确认支付(${orderPlat.total})</botton>
        </div>
    </div>
</body>

<script src="${resources}/plugins/jquery/2.2.2/jquery.min.js"></script>
<script src="${resources}/js/common.js"></script>
<script>
			//分享方法
			/*
			wxJs.setPrefix('${path}');
			var corpid = '${corpid}';
			var wxappid = '${wxappid}';
			var reurl=window.location.href.split('#')[0];
			var isWxBrowser = wxJs.isWeixin();
			//微信浏览器登陆 先 获取wxno  设置客户
			if(isWxBrowser){
				//异步获取微信jS-SDK 参数
				wx_Share(reurl,corpid,wxappid,null);
			}
			*/
		
			//调用微信支付
			function goWxPay(){
				
				$(".sendBtn").prop("disabled","disabled");
				$(".sendBtn").css("background-color", "#ccc");
				
				if (typeof WeixinJSBridge == "undefined"){
					
				   if( document.addEventListener ){
				       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
				   }else if (document.attachEvent){
				       document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
				       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
				   }
				}else{
				
					//支付宝支付 收费操作
		    		//alert("支付提交中....");
					//微信生成的预支付
					$.ajax({
						url:"${path}/pay/wxgopay/${orderPlat.id}",
						type:"post",
						data:{
							openid:'${membership.openid}',
							ts:(new Date()).getTime()
						},
						success:function(data){
							//提交成功
							if(data.code=='01'){
								
								onBridgeReady(data.result.appId,data.result.timeStamp,data.result.nonceStr,data.result.package,data.result.paySign,data.result.total);
								return;
							}
							else{
								common.alert({content:data.msg});
							}
						},
						error:function(){
							common.alert({content:'微信支付提交失败'});
						}   
			  		});
					
				}
	}
			
	function onBridgeReady(appId,timeStamp,nonceStr,packagepra,paySign,total){
	   WeixinJSBridge.invoke(
	       'getBrandWCPayRequest', {
	           "appId" : appId,     				//公众号名称，由商户传入     
	           "timeStamp":timeStamp,         		//时间戳，自1970年以来的秒数     
	           "nonceStr" : nonceStr, 				//随机串     
	           "package" : packagepra,   			//"prepay_id=u802345jgfjsdfgsdg888"订单详情扩展字符串 统一下单接口返回的prepay_id参数值，提交格式如：prepay_id=*** 
	           "signType" : "MD5",         			//微信签名方式:     
	           "paySign" : paySign 					//微信签名 
	       },
	       function(res){   
   				if(res.err_msg == "get_brand_wcpay_request:ok" ) {
	            	// 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
	            	window.location.href="${path}/manage/order/status/3";
			   	} 
	           	else if(res.err_msg == "get_brand_wcpay_request:cancel" ){
	           		common.alert({content:'支付过程中用户取消'});
	           	}
	           else if(res.err_msg == "get_brand_wcpay_request:fail" ){
	          	 	//支付失败
	          	 	common.alert({content:'支付失败'});
	           }else{
	        	   common.alert({content:'系统错误'});
	           }
	       }
	   ); 
	}
</script>	

</html>